package com.wbl.tijiancms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wbl.tijiancms.pojo.Cidetailedreport;
import com.wbl.tijiancms.pojo.Cireport;
import com.wbl.tijiancms.response.ApiRestResponse;
import com.wbl.tijiancms.response.TijianExceptionEnum;
import com.wbl.tijiancms.service.CidetailedreportService;
import com.wbl.tijiancms.mapper.CidetailedreportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author yy
* @description 针对表【cidetailedreport】的数据库操作Service实现
* @createDate 2024-09-18 10:09:07
*/
@Service
public class CidetailedreportServiceImpl extends ServiceImpl<CidetailedreportMapper, Cidetailedreport>
    implements CidetailedreportService{

    @Autowired
    CidetailedreportMapper cidetailedreportMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ApiRestResponse createDetailed(List<Cidetailedreport> cidetailedreports) throws Exception{
        QueryWrapper<Cidetailedreport> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderid", cidetailedreports.get(0).getOrderid());
        queryWrapper.eq("ciid", cidetailedreports.get(0).getCiid());
        List<Cidetailedreport> cireport = cidetailedreportMapper.selectList(queryWrapper);
//        System.out.println(!cireport.isEmpty());
        if (!(cireport.isEmpty())){
            return ApiRestResponse.success("已插入");
        }
        int i = cidetailedreportMapper.insertList(cidetailedreports);
        if (i>0){
            return ApiRestResponse.success(cidetailedreports);
        }
        return ApiRestResponse.error(TijianExceptionEnum.SYSTEM_ERROR);
    }
}




